$(function () {
    $("body").on('click','#nextStep',function () {//下一步
        var mobile = $("input[name='mobile']").val();
        var mobileCode = $("input[name='mobileCode']").val();
        $.ajax({
            url:baseloaction +'/mobile/user/verificationMobileCode',
            type:'post',
            dataType:'json',
            data:{
                'mobile':mobile,
                'mobileCode':mobileCode
            },
            success:function (result) {
                //验证成功
                if(result.success==true){
                    $("#forget-one").addClass("hide");
                    $("#forget-two").removeClass("hide");
                }else{
                    $.toast(result.message);
                }
            },
            error:function (error) {
                $.toast('系统错误，手机号验证失败');
            }
        });
    }).on('click','#resetPwBtn',function () {//完成
        var mobile = $("input[name='mobile']").val();
        var mobileCode = $("input[name='mobileCode']").val();
        var passWord = $("input[name='password']").val();
        var confirmPwd = $("input[name='confirmPwd']").val();
        if(passWord !=null && $.trim(passWord)!=''){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            passWord= encrypt.encrypt(passWord);
        }
        if(confirmPwd !=null && $.trim(confirmPwd)!=''){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            confirmPwd= encrypt.encrypt(confirmPwd);
        }
        $.ajax({
            url:baseloaction +'/mobile/user/ajax/retrievePassword',
            type:'post',
            dataType:'json',
            data:{
                'mobile':mobile,
                'mobileCode':mobileCode,
                'password':passWord,
                'confirmPwd':confirmPwd,
                "sign":sign
            },
            success:function (result) {
                $.toast(result.message);
                if(result.success==true){
                    $("input[name='mobile']").val('');
                    $("input[name='mobileCode']").val('');
                    $("input[name='password']").val('');
                    $("input[name='confirmPwd']").val('');
                    window.location.href = baseloaction +'/mobile/user/login'
                }else{
                    sign = result.keyMap.sign;
                    publicKey = result.keyMap.publicKey;
                }
            },
            error:function (error) {
                $.toast('系统错误，提交失败');
            }
        });
    }).on('click','#sendRand',function () {//发送验手机证码
        var _that = this;
        disabledSend(_that);
        var mobile = $("input[name='mobile']").val();
        sendCode(mobile,2,function () {
            $(_that).hide();
            $("#countdown").show();
            $("#countdown").text('(60s)后重新获取');
            var time = 60;
            var inter = setInterval(function () {
                time --;
                if(time<=0){
                    window.clearInterval(inter);
                    $(_that).show();
                    $("#countdown").hide();
                    relieveSend(_that);
                }else{
                    $("#countdown").text('('+time+'s)后重新获取');
                }
            },1000);
        },_that);
    });
});